const jwt = require('jsonwebtoken')
const config = require('../config')

function verifyToken(token) {
    return new Promise((resolve, reject) => {
        jwt.verify(token, config.privateKey, function (err, decoded) {
            if (err) {
                reject(err)
            }
            resolve(decoded)
        });
    })

}


function sign(data) {
    return new Promise((resolve, reject) => {
        jwt.sign(data, config.privateKey, function (err, token) {
            if (err) {
                reject(err)
            }
            resolve(token)
        })
    })

}



module.exports = {
    sign,
    verifyToken
}